<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
	layout:decorate="~{layout/simple}">
<head>
	<title>绑定</title>
</head>
<body>
<th:block layout:fragment="page-content">
	<header class="wx-header">
      <h1 class="wx-title">绑定彩伞</h1>
    </header>
    <form id="form">
		<div class="weui_cells weui_cells_form">
			<div class="weui_cell">
				<div class="weui_cell_hd">
					<label class="weui_label">账户</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input class="weui_input" name="username" type="text" placeholder="邮箱地址或者手机号码">
				</div>
				<div class="weui_cell_ft">
                	<i class="weui_icon_warn"></i>
            	</div>
			</div>
			<div class="weui_cell">
				<div class="weui_cell_hd">
					<label class="weui_label">密码</label>
				</div>
				<div class="weui_cell_bd weui_cell_primary">
					<input class="weui_input" name="password" type="password" placeholder="您的密码">
				</div>
				<div class="weui_cell_ft">
	                <i class="weui_icon_warn"></i>
	            </div>
			</div>
		</div>
		
		<div class="weui_cells_title">
			<div class="inline left">你还没有账号？ <a th:href="@{/user/register}">创建账号</a></div>
			<div class="inline right"><a th:href="@{/user/forgot}">忘记密码</a></div>
		</div>
	
		<div class="weui_btn_area">
			<button id="formSubmitBtn" class="weui_btn weui_btn_primary" type="submit">绑定</button>
		</div>
	</form>

	</th:block>
<th:block layout:fragment="page-js">
<script type="text/javascript">
$(function(){
	function ajaxSubmitForm(){
		$.ajax({
			type: 'post',
			url: contextPath + '/user/login',
			data: $("#form").serialize(),
			dataType: 'json',
			beforeSend: function(){
				$.showLoading('正在处理');
			},
			success: function(result){
				$.hideLoading();
				if(result.success){
					//$.alert("恭喜您，绑定成功！", "标题", function(){
					location.href = contextPath + "/wechat/success?url="+contextPath+"/index&time=2&msg=恭喜您，绑定成功";
					//});
				} else {
					$.toast(result.message, "forbidden");
				}
			}
		});
	}
	
	$("#form").validate({
		 rules : {
			 username: {
				 required: true,
				 phoneOrEmail: true
			 },
			 password: {
				 required: true,
				 minlength: 6
			 }
			 
		 },
		 messages: {
			 username: {
				 phoneOrEmail: "邮箱地址或者手机号码格式不正确"
			 },
			 password: {
				 minlength: $.validator.format("密码至少 {0} 位")
			 }
		 },
		 submitHandler: function(form){
			 ajaxSubmitForm();
			 return false;
		 }
		 
	});
});
</script>
</th:block>
</body>
</html>
